package com.lx.serv.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.lx.dao.UserConsumeDao;
import com.lx.dao.UserDao;
import com.lx.domain.userconsume;
import com.lx.domain.users;
import com.lx.serv.UserServ;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class UserServImpl implements UserServ {
    @Autowired
    UserDao userDao;
    @Autowired
    UserConsumeDao userConsumeDao;

    @Override
    public List<users> getAll() {
        return userDao.selectList(null);
    }

    @Override
    public boolean add(users user) {
        return userDao.insert(user) > 0;
    }

    @Override
    public boolean update(users user) {
        LambdaUpdateWrapper<users> lqw = new LambdaUpdateWrapper<users>();
        lqw.eq(users::getId, user.getId());
        return userDao.update(user, lqw) > 0;
    }

    @Override
    public boolean delete(int id) {
        return userDao.deleteById(id) > 0;
    }

    @Override
    public List<userconsume> getHot() {
        return userConsumeDao.HotUsers();
    }
}
